package com.neusoft.liduan.d0915;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;


public class CanvasFrame extends JFrame implements ActionListener{
	private CanvasPanel canvas;
	
	public CanvasFrame() {
		setSize(450, 550);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setTitle("东软画图软件");
		// 居中显示
		setLocationRelativeTo(null);
		//设置布局管理器
		setLayout(new BorderLayout());
		//创建按钮面板
		JPanel pBtns = new JPanel(new FlowLayout());
		ButtonGroup bg = new ButtonGroup();
		JRadioButton rb = new JRadioButton("直线");
		rb.setActionCommand("l");
		rb.addActionListener(this);
		rb.setSelected(true);
		bg.add(rb);
		pBtns.add(rb);
		
		rb = new JRadioButton("矩形");
		rb.setActionCommand("s");
		rb.addActionListener(this);
		bg.add(rb);
		pBtns.add(rb);
		
		rb = new JRadioButton("圆");
		rb.setActionCommand("c");
		rb.addActionListener(this);
		bg.add(rb);
		pBtns.add(rb);
		
		add(pBtns, BorderLayout.NORTH);
		//画图面板
		canvas = new CanvasPanel();
		add(canvas, BorderLayout.CENTER);
		setVisible(true);
	}

	
	public static void main(String[] args) {
		new CanvasFrame();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String command = e.getActionCommand();
		canvas.setType(command);
		switch (command) {
		case "l":
			System.out.println("直线");
			break;
		case "s":
			System.out.println("矩形");
			break;
		case "c":
			System.out.println("圆形");
			break;

		default:
			break;
		}
//		canvas.repaint();//刷新
	}

//	@Override
//	public void stateChanged(ChangeEvent e) {
//		String command = e.getSource();
//		switch (command) {
//		case "line":
//			System.out.println("直线");
//			break;
//
//		default:
//			break;
//		}
//		AbstractButton aButton = (AbstractButton)e.getSource();
//        ButtonModel aModel = aButton.getModel();
//        boolean armed = aModel.isArmed();
//        boolean pressed = aModel.isPressed();
//        boolean selected = aModel.isSelected();
//        System.out.println("Changed: " + armed + "/" + pressed + "/" +
//          selected);
//	}
}
